import type { MutipleType } from '@/types';
import type { BeOption, SelectOption } from '@/types/option';

// 枚举
interface Item {
	value: string | number;
	label: string;
}

export const createEnum = (options: Item[]) => {
	const map = options.reduce((acc, cur) => {
		acc[cur.value] = cur.label;
		return acc;
	}, {} as Record<string, string>);
	return {
		map,
		options
	};
};

// 根据后端数据生成options
export function generateOptionsAndMap(data: BeOption[]) {
	const options: SelectOption[] = [];
	const map: Map<MutipleType, string> = new Map();
	if (Array.isArray(data)) {
		for (const v of data) {
			options.push({
				// value: String(v.ID),
				value: v.ID,
				label: v.Name,
			});
			// map.set(String(v.ID), v.Name);
			map.set(v.ID, v.Name);
		}
	}
	return {
		map,
		options
	};
}
